//
//  YCAddFriendViewController.m
//  YCSchool
//
//  Created by gmall on 16/5/11.
//  Copyright © 2016年 yanglinxia. All rights reserved.
//  添加好友等主页

#import "YCAddFriendViewController.h"
#import "YCFriendSearchViewController.h"
#import "YCFriendConditionViewController.h"
#import "YCFriendNearbyViewController.h"
#import "YCFriendSmartViewController.h"
#import "YCFriendMatchViewController.h"

@interface YCAddFriendViewController ()

@property (readonly ,nonatomic) UIView *firstView;
@property (readonly ,nonatomic) UIButton *searcFriendsButton;
@property (readonly ,nonatomic) UIView *secondView;

@property (readonly ,nonatomic) UIButton *conditionSearchButton;
@property (readonly ,nonatomic) UIButton *nearbySearchButton;
@property (readonly ,nonatomic) UIButton *smartSearchButton;
@property (readonly ,nonatomic) UIButton *phoneNickerSearchButton;

@end

@implementation YCAddFriendViewController

@synthesize firstView = _firstView;
@synthesize searcFriendsButton = _searcFriendsButton;
@synthesize secondView = _secondView;
@synthesize conditionSearchButton = _conditionSearchButton;
@synthesize nearbySearchButton =_nearbySearchButton;
@synthesize phoneNickerSearchButton = _phoneNickerSearchButton;
@synthesize smartSearchButton = _smartSearchButton;

#pragma mark - 属性获取方法

- (UIView *)firstView
{
    if (!_firstView)
    {
        _firstView = [[UIView alloc] init];
        _firstView.backgroundColor = [UIColor whiteColor];
    }
    
    return _firstView;
}

// 搜索条
- (UIButton *)searcFriendsButton
{
    if (!_searcFriendsButton)
    {
        _searcFriendsButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_searcFriendsButton setTitle:@"输入昵称/手机号" forState:UIControlStateNormal];
        [_searcFriendsButton setTitleColor:[UIColor yc_colorWithUInt:0x8c8c8c] forState:UIControlStateNormal];
        _searcFriendsButton.backgroundColor = [UIColor yc_colorWithUInt:0xeaebed];
        _searcFriendsButton.layer.cornerRadius = 5;
        _searcFriendsButton.layer.masksToBounds = YES;
        _searcFriendsButton.titleLabel.font = [UIFont systemFontOfSize:13];
        [_searcFriendsButton setImage:[UIImage imageNamed:@"search_friends"] forState:UIControlStateNormal];
        _searcFriendsButton.imageView.contentMode = UIViewContentModeCenter;
        [_searcFriendsButton addTarget:self action:@selector(didTouchUpInsideSearchFriendsButton:) forControlEvents:UIControlEventTouchUpInside];
    }
    
    return _searcFriendsButton;
}

- (UIView *)secondView
{
    if (!_secondView)
    {
        _secondView = [[UIView alloc] init];
        _secondView.backgroundColor = [UIColor whiteColor];
    }
    
    return _secondView;
}

// 条件探索
- (UIButton *)conditionSearchButton
{
    if (!_conditionSearchButton)
    {
        _conditionSearchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_conditionSearchButton addTarget:self action:@selector(didTouchUpInsideConditionSearchButton:) forControlEvents:UIControlEventTouchUpInside];
        _conditionSearchButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _conditionSearchButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
        [_conditionSearchButton setImage:[UIImage imageNamed:@"按条件查找"] forState:UIControlStateNormal];
        [_conditionSearchButton setTitle:@"按条件查找" forState:UIControlStateNormal];
        [_conditionSearchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    return _conditionSearchButton;
}

// 附近的人
- (UIButton *)nearbySearchButton
{
    if (!_nearbySearchButton)
    {
        _nearbySearchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_nearbySearchButton addTarget:self action:@selector(didTouchUpInsideNearbySearchButton:) forControlEvents:UIControlEventTouchUpInside];
        _nearbySearchButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _nearbySearchButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
       [_nearbySearchButton setImage:[UIImage imageNamed:@"查看附近的人"] forState:UIControlStateNormal];
        [_nearbySearchButton setTitle:@"查看附近的人" forState:UIControlStateNormal];
        [_nearbySearchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    return _nearbySearchButton;
}


// 智能推荐
- (UIButton *)smartSearchButton
{
    if (!_smartSearchButton)
    {
        _smartSearchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_smartSearchButton addTarget:self action:@selector(didTouchUpInsideSmartSearchButton:) forControlEvents:UIControlEventTouchUpInside];
        _smartSearchButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _smartSearchButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
        [_smartSearchButton setImage:[UIImage imageNamed:@"智能推荐"] forState:UIControlStateNormal];
        [_smartSearchButton setTitle:@"智能推荐" forState:UIControlStateNormal];
        [_smartSearchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    return _smartSearchButton;
}


// 添加手机联系人
- (UIButton *)phoneNickerSearchButton
{
    if (!_phoneNickerSearchButton)
    {
        _phoneNickerSearchButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_phoneNickerSearchButton setImage:[UIImage imageNamed:@"next_friends"] forState:UIControlStateNormal];
        _phoneNickerSearchButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _phoneNickerSearchButton.imageEdgeInsets = UIEdgeInsetsMake(0,-10, 0, 0);
        [_phoneNickerSearchButton addTarget:self action:@selector(didTouchUpInsidePhoneNickerSearchButton:) forControlEvents:UIControlEventTouchUpInside];
        [_phoneNickerSearchButton setImage:[UIImage imageNamed:@"添加手机联系人"] forState:UIControlStateNormal];
        [_phoneNickerSearchButton setTitle:@"添加手机联系人" forState:UIControlStateNormal];
        [_phoneNickerSearchButton setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    }
    
    return _phoneNickerSearchButton;
}

#pragma mark - 视图控制器生命周期

- (void)dealloc
{
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor yc_colorWithUInt:0xf7f7f7];
    
    self.title = NSLocalizedString(@"添加好友", nil);
    [self yc_addBackBarButtonItem];
    
    [self layout];
}

#pragma mark - 自定义的方法

- (void)layout
{
    [self.view addSubview:self.firstView];
    [self.firstView addSubview:self.searcFriendsButton];
    [self.view addSubview:self.secondView];
    [self.secondView addSubview:self.conditionSearchButton];
    [self.secondView addSubview:self.smartSearchButton];
    [self.secondView addSubview:self.phoneNickerSearchButton];
    [self.secondView addSubview:self.nearbySearchButton];
    
    [self.searcFriendsButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.firstView);
        make.left.equalTo(self.firstView).offset(30);
        make.right.equalTo(self.firstView).offset(-30);
        make.height.equalTo(@35);
    }];
    
    [self.firstView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self.view);
        make.bottom.equalTo(self.searcFriendsButton.mas_bottom).with.offset(20);
    }];
    
    [self.conditionSearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.secondView).offset(heightFromIphone6Height(30));
        make.left.equalTo(self.secondView).offset(25);
//        make.width.equalTo(@(kScreenWidth / 2 - 60));
        make.height.equalTo(@40);
    }];
    
    [self.smartSearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.conditionSearchButton.mas_bottom).offset(15);
        make.left.equalTo(self.secondView).offset(25);
//        make.width.equalTo(@(kScreenWidth / 2 - 60));
        make.height.equalTo(@40);
    }];
    
    [self.phoneNickerSearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.smartSearchButton.mas_bottom).offset(15);
        make.left.equalTo(self.secondView).offset(25);
//        make.width.equalTo(@(kScreenWidth / 2 - 60));
        make.height.equalTo(@40);
    }];
    
    
    [self.nearbySearchButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.phoneNickerSearchButton.mas_bottom).offset(15);
        make.left.equalTo(self.secondView).offset(25);
//        make.width.equalTo(@(kScreenWidth / 2 - 60));
        make.height.equalTo(@40);
    }];
    
    [self.secondView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.equalTo(self.view);
        make.top.equalTo(self.firstView.mas_bottom);
        make.bottom.equalTo(self.view);
    }];
}

#pragma mark - 点击事件

// 点击搜索条
- (void)didTouchUpInsideSearchFriendsButton:(UIButton *)button
{
    YCFriendSearchViewController *vc = [[YCFriendSearchViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 条件搜索
- (void)didTouchUpInsideConditionSearchButton:(UIButton *)button
{
    YCLogFunc
    YCFriendConditionViewController *vc = [[YCFriendConditionViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 智能推荐
- (void)didTouchUpInsideSmartSearchButton:(UIButton *)button
{
    YCLogFunc
    YCFriendSmartViewController *vc = [[YCFriendSmartViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 附近的人
- (void)didTouchUpInsideNearbySearchButton:(UIButton *)button
{
    YCLogFunc
    YCFriendNearbyViewController *vc = [[YCFriendNearbyViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

// 添加手机联系人
- (void)didTouchUpInsidePhoneNickerSearchButton:(UIButton *)button
{
    YCLogFunc
    YCFriendMatchViewController *vc = [[YCFriendMatchViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}


@end
